
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>图书管理</title>
    <base href="${pageContext.request.scheme}://${pageContext.request.serverName}:${pageContext.request.serverPort}${pageContext.request.contextPath}/pages/Manage/BookManager.jsp"/>
    <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<style>
    h2{
        text-align: center;
    }
    #div2{
        margin-left:1100px;
    }
    #div3{
        margin:0 auto;
        text-align: center;
    }
</style>
    <script type="text/javascript" src="../../Jquery/jquery-1.8.3.js"></script>
    <script type="text/javascript">
        $(function() {
            $(".delete").click(function() {
                var name=$(this).parent().parent().find(":eq(1)").text();
                var id=$(this).parent().prev().prev().prev().prev().prev().prev().prev().text();
                if(confirm("你确定要删除"+name+"吗")){
                    $(this).attr("href","../../books?action=deleteBook&pageNow=${pages.pageNow}&pageSize=${pages.pageSize}&id="+id);
                }else{
                    return false;
                }
            });
            $("#bu1").click(function() {
                var pageNo=$("#skip").val();
                var pageTotal=$("#pageT");

                if(pageNo<1||pageNo>pageTotal){
                    alert("非法输入，请重新输入!");
                }else {
                    var pageSize = $("#pageS").val();
                    location.href = "${pageContext.request.scheme}://${pageContext.request.serverName}:${pageContext.request.serverPort}${pageContext.request.contextPath}/books?action=PageManage&pageNow=" + pageNo + "&pageSize=" + pageSize;
                }
            });
        });
    </script>
</head>
<body>
<h2>这是图书管理界面</h2>
<div id="div1">
<table border="1" cellspacing="0" align="center">
    <caption>图书信息列表</caption>
    <tr><th>id</th><th>书名</th><th>价格</th><th>库存</th><th>作者</th><th>销量</th><th>图片路径</th>
        <th>操作</th>
    </tr>
<c:forEach items="${bookss}" var="book">
    <tr><td>${book.id}</td><td>${book.name}</td><td>${book.price}</td><td>${book.stock}</td><td>${book.author}</td>
        <td>${book.sale}</td>
        <td>${book.imgPath}</td>
        <td><a href="../../books?action=deleteBook&pageNow=${pages.pageNow}&pageSize=${pages.pageSize}&id=" class="delete">删除</a>
            <a href="../../books?action=queryABook&id=${book.id}&pageNow=${pages.pageNow}&pageSize=${pages.pageSize}">修改</a>
        </td>
        </tr>
</c:forEach>
</table>
    <div id="div3">
    <c:if test="${pages.pageNow!=1}">
        <a href="../../books?action=PageManage&pageNow=1&pageSize=${pages.pageSize}">首页</a>
        <a href="../../books?action=PageManage&pageNow=${pages.pageNow-1}&pageSize=${pages.pageSize}">上一页</a>
    </c:if>
    <form action="../../books?action=PageManage" method="post" name="pageInfo">
    当前页码:<input type="text" name="pageNow" value="${pages.pageNow}"/>&nbsp;&nbsp;&nbsp; 每页记录条数:<input type="text" name="pageSize" value="${pages.pageSize}"/>
        <input type="submit" value="刷新"/>
    </form>
<c:if test="${pages.pageNow!=pages.pageTotal}">
    <a href="../../books?action=PageManage&pageNow=${pages.pageNow+1}&pageSize=${pages.pageSize}">下一页</a>
    <a href="../../books?action=PageManage&pageNow=${pages.pageTotal}&pageSize=${pages.pageSize}">末页</a>
</c:if>
    总页码:${pages.pageTotal}&nbsp;&nbsp;&nbsp;总记录数:${pages.countTotal}<br/>
        <c:choose>
            <c:when test="${pages.pageTotal<=5}">
                <c:forEach begin="1" end="${pages.pageTotal}" var="i">
                    <c:if test="${pages.pageNow==i}">
                        第【${i}】页
                    </c:if>
                    <c:if test="${pages.pageNow!=i}">
                        <a href="../../books?action=PageManage&pageNow=${i}&pageSize=${pages.pageSize}">第${i}页</a>
                    </c:if>
                </c:forEach>
            </c:when>
            <c:otherwise>
                  <c:choose>
                       <c:when test="${pages.pageNow==1||pages.pageNow==2}">
                        <c:forEach begin="1" end="5" var="i">
                            <c:if test="${pages.pageNow==i}">
                                第【${i}】页
                            </c:if>
                            <c:if test="${pages.pageNow!=i}">
                                <a href="../../books?action=PageManage&pageNow=${i}&pageSize=${pages.pageSize}">第${i}页</a>
                            </c:if>
                        </c:forEach>
                       </c:when>
                      <c:when test="${pages.pageNow==pages.pageTotal-1||pages.pageNow==pages.pageTotal}">
                          <c:forEach begin="${pages.pageTotal-4}" end="${pages.pageTotal}" var="i">
                              <c:if test="${pages.pageNow==i}">
                                  第【${i}】页
                              </c:if>
                              <c:if test="${pages.pageNow!=i}">
                                  <a href="../../books?action=PageManage&pageNow=${i}&pageSize=${pages.pageSize}">第${i}页</a>
                              </c:if>
                          </c:forEach>
                      </c:when>
                      <c:otherwise>
                          <c:forEach begin="${pages.pageNow-2}" end="${pages.pageNow+2}" var="i">
                              <c:if test="${pages.pageNow==i}">
                                  第【${i}】页
                              </c:if>
                              <c:if test="${pages.pageNow!=i}">
                                  <a href="../../books?action=PageManage&pageNow=${i}&pageSize=${pages.pageSize}">第${i}页</a>
                              </c:if>
                          </c:forEach>
                      </c:otherwise>
                  </c:choose>
            </c:otherwise>
        </c:choose>
        <input type="hidden" value="${pages.pageSize}" id="pageS"/><input type="hidden" value="${pages.pageTotal}" id="pageT"/>
        调到第<input type="text" id="skip" value="${pages.pageNow}"/>页 <button id="bu1">跳转</button>
    </div>
</div><br/><br/><br/><br/><br/><br/><br/><br/>
<div id="div2">
<a href="BookEdit.jsp?pageTotal=${pages.pageTotal}&pageSize=${pages.pageSize}">增加图书</a>
</div>
</body>
</html>
